﻿<?xml version="1.0" encoding="utf-8" ?>
<Batch 
    xmlns="http://schemas.dbshell.com/core"
    xmlns:rds="http://schemas.dbshell.com/datasync"
    >
    <rds:SyncModel >
        <rds:SyncModel.Sources>
            <rds:Source DataSource="{Table Source}">
                <rds:SourceColumn Name="SourceId" />
                <rds:SourceColumn Name="Value" />
                <rds:SourceColumn Name="IsInGroup" />
            </rds:Source>
        </rds:SyncModel.Sources>
        <rds:SyncModel.Targets>
            <rds:Target TableName="TargetItem">
				<!--
                <rds:TargetColumn Name="TargetItemId" />
				-->
                <rds:TargetColumn Name="TargetIdOriginal" Source="SourceId" IsKey="True" />
                <rds:TargetColumn Name="Value" Source="Value" />
            </rds:Target>

            <rds:Target TableName="TargetGroup">
                <rds:TargetColumn Name="IsImported" Value="1" IsRestriction="True" />
				<!--
                <rds:TargetColumn Name="TargetGroupId" />
                <rds:TargetColumn Name="TargetCategoryId" />
				-->
            </rds:Target>
		
            <rds:Target TableName="TargetItemGroup">
				<!--
                <rds:TargetColumn Name="TargetItemId" />
                <rds:TargetColumn Name="TargetGroupId" />
				-->
				<rds:Target.AdditionalFilters>
					<rds:AdditionalFilter Column="IsInGroup" Filter="1" />
				</rds:Target.AdditionalFilters>
                <rds:Target.LifetimeHandler>
                    <rds:SimpleLifetimeHandler Delete="True" />
                </rds:Target.LifetimeHandler>
				
            </rds:Target>
        </rds:SyncModel.Targets>

        <rds:SyncModel.TargetReferences>
			<rds:TargetReference Source="TargetItemGroup" Target="TargetItem" IsKey="True" >
				<rds:TargetReferenceColumn BaseName="TargetItemId" RefName="TargetItemId" />
			</rds:TargetReference>
			<rds:TargetReference Source="TargetItemGroup" Target="TargetGroup" IsRestriction="True" >
				<rds:TargetReferenceColumn BaseName="TargetGroupId" RefName="TargetGroupId" />
			</rds:TargetReference>
        </rds:SyncModel.TargetReferences>
    </rds:SyncModel>
    
    <rds:CreateProcedure ProcName="RunSync" />
</Batch>
